package com.myapp.wicket;

import org.apache.wicket.Page;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.html.WebPage;

public final class Index extends WebPage implements AuthenticatedWebPage {

    public Index() {
        super();
        final SignInSession session = (SignInSession)getSession();
        add(new HeaderPanel("headerPanel", "hello"));
        add(new Link("makeAnOrderLink")
        {
            @Override
            public void onClick()
            {
                if(session.getRole().equalsIgnoreCase("customer"))
                {
                    setResponsePage(HomePage.class);
                }
                else
                {
                    setResponsePage(RedirectToIndexPage.class);
                }
            }
        });
        add(new Link("createProductLink")
        {
            @Override
            public void onClick()
            {
                if(session.getRole().equalsIgnoreCase("admin"))
                {
                    setResponsePage(AddNewProductPage.class);
                }
                else
                {
                    setResponsePage(RedirectToIndexPage.class);
                }
            }
        });
        add(new Link("confirmOrderLink")
        {
            @Override
            public void onClick()
            {
                if(session.getRole().equalsIgnoreCase("admin"))
                {
                    setResponsePage(WatchConfirmedOrdersPage.class);
                }
                else
                {
                    setResponsePage(RedirectToIndexPage.class);
                }
            }
        });
    }
}
